package cn.herlioner.service;

import cn.herlioner.dao.ObjectDAO;
import cn.herlioner.dao.impl.Obj_StuDAOImpl;
import cn.herlioner.dao.impl.ObjectDAOImpl;
import cn.herlioner.pojo.Obj_Stu;
import cn.herlioner.pojo.TSObject;

public class SelectobjServiceImpl implements SelectobjService{
	Obj_StuDAOImpl obj_StuDAO = new Obj_StuDAOImpl();
	Obj_Stu obj_Stu = new Obj_Stu();
	ObjectDAOImpl objectDAOImpl = new ObjectDAOImpl();
	TSObject tsObject = new TSObject();
	@Override
	public void saveselectobj(Long stunum, Long objnum, int[] bookselect) {
		for (int  BS : bookselect) {
			//判断学生选择该课程是否同时购买书籍，bookselect[]数组内存在与objnum相同的数字说明购买书�?
			if(BS == objnum){
				//1表示购买书籍
				obj_Stu.setBook((long) 1);
				obj_Stu.setObjnum(objnum);
				obj_Stu.setStunum(stunum);
				obj_StuDAO.add(obj_Stu);
				//余量减一
				tsObject = objectDAOImpl.get(objnum).get(0);
				tsObject.toString();
				long i = tsObject.getAllowance()-1;
				tsObject.setAllowance(i);
				tsObject.toString();
				objectDAOImpl.update(tsObject);
			}else{
				//0表示不购买书籍
				obj_Stu.setBook((long) 0);
				obj_Stu.setObjnum(objnum);
				obj_Stu.setStunum(stunum);
				obj_StuDAO.add(obj_Stu);
				//余量减一
				tsObject = objectDAOImpl.get(objnum).get(0);
				tsObject.toString();
				long i = tsObject.getAllowance()-1;
				tsObject.setAllowance(i);
				tsObject.toString();
				objectDAOImpl.update(tsObject);
			}
		}
	}
}

